package com.shijun.im.http;

import com.shijun.im.bean.RequestTokenBean;
import com.shijun.im.bean.SimplRequestBean;
import com.shijun.im.config.HttpUrlAPI;

import java.util.Map;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.PartMap;
import retrofit2.http.Query;
import retrofit2.http.Url;
import rx.Observable;

/**
 * Created by Administrator on 2017/9/9 0009.
 */

public interface APIInterface {
    @GET(HttpUrlAPI.UPLOADAVATAR)
    Call<RequestTokenBean> repo(@Query("name") String name, @Query("password") String password);

    @FormUrlEncoded
    @POST(HttpUrlAPI.REGISTER)
    Call<SimplRequestBean> register(@FieldMap Map<String, String> params);

    //单图片上传，带描述（MultipartBody.Part）
    @Multipart
    @POST("upload")
    Call<ResponseBody> upload(@Part("description") RequestBody description,
                              @Part MultipartBody.Part file);
//    如果你用retrofit2.0以上的版本 MultipartBody.Part的参数不能指定part() 的Key，否则会报如下异常：
//    java.lang.IllegalArgumentException: @Part parameters using the MultipartBody.Part must not include a part name in the annotation. (parameter #2)


    //单图片上传，不带描述（RequestBody）
    @Multipart
    @POST("you methd url upload/")
    Call<ResponseBody> uploadFile(
            @Part() RequestBody file);

    //确定参数的多图片上传
    @POST("upload/")
    Call<ResponseBody> uploadFiles(@Part("filename") String description,
                                   @Part("pic\"; filename=\"image1.png") RequestBody imgs1,
                                   @Part("pic\"; filename=\"image2.png") RequestBody imgs2,
                                   @Part("pic\"; filename=\"image3.png") RequestBody imgs3,
                                   @Part("pic\"; filename=\"image4.png") RequestBody imgs4);

    //不确定参数的图片上传
    @Multipart
    @POST()
    Observable<ResponseBody> uploadFiles(
            @Url String url,
            @PartMap() Map<String, RequestBody> maps);

    //图文同时上报
    @Multipart
    @POST("upload/")
    Call<ResponseBody> register(
            @FieldMap Map<String, String> usermaps,
            @Part("avatar\"; filename=\"avatar.jpg") RequestBody avatar);


    // 更简单的用Body方式：
    @POST()
    Call<ResponseBody> upLoad(
            @Url() String url,
            @Body RequestBody Body);

    //如果支持RxJava
    @POST()
    Observable<ResponseBody> upLoadRxJava(
            @Url() String url,
            @Body RequestBody Body);

}
